<!DOCTYPE html>
<html>
<head>
    

    

    



    <meta charset="utf-8">
    
    
    
    <title>GraphQL Learn (1) - Queries and Mutations | Sailing | Sailing&#39;s Home</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="GraphQL">
    <meta name="description" content="在此页面上，你将详细了解如何查询GrahQL服务器。 字段（Fields）最简单的，GraphQL是关于要求对象上的特定字段。我们先来看一个非常简单的查询，当我们运行它时得到结果： 12345&amp;#123;  hero &amp;#123;    name  &amp;#125;&amp;#125; 123456">
<meta name="keywords" content="GraphQL">
<meta property="og:type" content="article">
<meta property="og:title" content="GraphQL Learn (1) - Queries and Mutations">
<meta property="og:url" content="http://lishangying.github.io/2017/08/15/GraphQL Learn (1) - Queries and Mutations/index.html">
<meta property="og:site_name" content="Sailing">
<meta property="og:description" content="在此页面上，你将详细了解如何查询GrahQL服务器。 字段（Fields）最简单的，GraphQL是关于要求对象上的特定字段。我们先来看一个非常简单的查询，当我们运行它时得到结果： 12345&amp;#123;  hero &amp;#123;    name  &amp;#125;&amp;#125; 1234567&amp;#123;  &quot;data&quot;: &amp;#123;    &quot;hero&quot;: &amp;#123;      &quot;name&quot;: &quot;">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2017-11-22T17:13:31.653Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="GraphQL Learn (1) - Queries and Mutations">
<meta name="twitter:description" content="在此页面上，你将详细了解如何查询GrahQL服务器。 字段（Fields）最简单的，GraphQL是关于要求对象上的特定字段。我们先来看一个非常简单的查询，当我们运行它时得到结果： 12345&amp;#123;  hero &amp;#123;    name  &amp;#125;&amp;#125; 1234567&amp;#123;  &quot;data&quot;: &amp;#123;    &quot;hero&quot;: &amp;#123;      &quot;name&quot;: &quot;">
    
        <link rel="alternate" type="application/atom+xml" title="Sailing" href="/atom.xml">
    
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">Sailing</h5>
          <a href="mailto:18810691321@163.com" title="18810691321@163.com" class="mail">18810691321@163.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                Archives
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                Tags
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/categories"  >
                <i class="icon icon-lg icon-th-list"></i>
                Categories
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="http://lishangying.github.io" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">GraphQL Learn (1) - Queries and Mutations</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">GraphQL Learn (1) - Queries and Mutations</h1>
        <h5 class="subtitle">
            
                <time datetime="2017-08-14T16:00:00.000Z" itemprop="datePublished" class="page-time">
  2017-08-15
</time>


	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/Web/">Web</a></li></ul>

            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#字段（Fields）"><span class="post-toc-number">1.</span> <span class="post-toc-text">字段（Fields）</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#参数（Arguments）"><span class="post-toc-number">2.</span> <span class="post-toc-text">参数（Arguments）</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#别名（Aliases）"><span class="post-toc-number">3.</span> <span class="post-toc-text">别名（Aliases）</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#片段（Fragments）"><span class="post-toc-number">4.</span> <span class="post-toc-text">片段（Fragments）</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#变量（variables）"><span class="post-toc-number">5.</span> <span class="post-toc-text">变量（variables）</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#变量定义"><span class="post-toc-number">5.1.</span> <span class="post-toc-text">变量定义</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#默认变量"><span class="post-toc-number">5.2.</span> <span class="post-toc-text">默认变量</span></a></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#操作名（Operation-name）"><span class="post-toc-number">6.</span> <span class="post-toc-text">操作名（Operation  name）</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#指令（Directives）"><span class="post-toc-number">7.</span> <span class="post-toc-text">指令（Directives）</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#修改（Mutations）"><span class="post-toc-number">8.</span> <span class="post-toc-text">修改（Mutations）</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#修改多个字段"><span class="post-toc-number">8.1.</span> <span class="post-toc-text">修改多个字段</span></a></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#内联片段（inline-Fragments）"><span class="post-toc-number">9.</span> <span class="post-toc-text">内联片段（inline Fragments）</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#元字段（Meta-fields）"><span class="post-toc-number">9.1.</span> <span class="post-toc-text">元字段（Meta fields）</span></a></li></ol></li></ol>
        </nav>
    </aside>
    
<article id="post-GraphQL Learn (1) - Queries and Mutations"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">GraphQL Learn (1) - Queries and Mutations</h1>
        <div class="post-meta">
            <time class="post-time" title="2017-08-15 00:00:00" datetime="2017-08-14T16:00:00.000Z"  itemprop="datePublished">2017-08-15</time>

            
	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/categories/Web/">Web</a></li></ul>



            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <p>在此页面上，你将详细了解如何查询GrahQL服务器。</p>
<h2 id="字段（Fields）"><a href="#字段（Fields）" class="headerlink" title="字段（Fields）"></a>字段（Fields）</h2><p>最简单的，GraphQL是关于要求对象上的特定字段。我们先来看一个非常简单的查询，当我们运行它时得到结果：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  hero &#123;</span><br><span class="line">    name</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="string">"data"</span>: &#123;</span><br><span class="line">    <span class="string">"hero"</span>: &#123;</span><br><span class="line">      <span class="string">"name"</span>: <span class="string">"R2-D2"</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>可以看到，查询与结果的形状完全相同。这对于GraphQL是至关重要的，因为您总是收到您期望的内容，并且服务器确切知道客户端要求哪些字段。<br><a id="more"></a><br>字段名返回一个String类型，在这种情况下是星球大战主角“R2-D2”的名称。</p>
<blockquote>
<p>哦，还有一件事: 上面的查询是互动的。这意味着您可以随意更改它，并看到新的结果。尝试在查询中向<code>hero</code>对象添加一个<code>appearIn</code>字段，并查看新结果。</p>
</blockquote>
<p>在前面的例子中，我们只是要求我们返回一个String类型的主角名字，但字段也可以引用对象。在这种情况下，您可以对该对象的字段进行子查询。 GraphQL查询可以遍历相关对象及其字段，让客户端在一个请求中获取大量相关数据，而不是像传统的REST架构中一样需要进行几次往返。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  hero &#123;</span><br><span class="line">    name</span><br><span class="line">    # Queries can have comments!</span><br><span class="line">    friends &#123;</span><br><span class="line">      name</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="string">"data"</span>: &#123;</span><br><span class="line">    <span class="string">"hero"</span>: &#123;</span><br><span class="line">      <span class="string">"name"</span>: <span class="string">"R2-D2"</span>,</span><br><span class="line">      <span class="string">"friends"</span>: [</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="string">"name"</span>: <span class="string">"Luke Skywalker"</span></span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="string">"name"</span>: <span class="string">"Han Solo"</span></span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="string">"name"</span>: <span class="string">"Leia Organa"</span></span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>请注意，在此示例中，<code>friends</code>字段返回一个项目数组。 GraphQL查询对于单个项或多个项列表写法上相同，但是我们根据schema中记录的内容知道预期获得的是哪一种。</p>
<h2 id="参数（Arguments）"><a href="#参数（Arguments）" class="headerlink" title="参数（Arguments）"></a>参数（Arguments）</h2><p>如果我们唯一可以做的是遍历对象及其字段，则GraphQL已经是数据提取的非常有用的语言。但是如果你还能将参数传递给字段的话，事情会变得更有趣。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  human(id: &quot;1000&quot;) &#123;</span><br><span class="line">    name</span><br><span class="line">    height</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="string">"data"</span>: &#123;</span><br><span class="line">    <span class="string">"human"</span>: &#123;</span><br><span class="line">      <span class="string">"name"</span>: <span class="string">"Luke Skywalker"</span>,</span><br><span class="line">      <span class="string">"height"</span>: <span class="number">1.72</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在像REST这样的系统中，您只能传递一组参数(paramter和url query)。但是在GraphQL中，每个字段和嵌套对象都可以获取自己的参数集，从而使一次GraphQL查询可以完全代替多个传统的API请求。您甚至可以将参数传递到标量字段中并在服务器上实现数据转换，而不需要在客户端上进行。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  human(id: &quot;1000&quot;) &#123;</span><br><span class="line">    name</span><br><span class="line">    height(unit: FOOT)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="string">"data"</span>: &#123;</span><br><span class="line">    <span class="string">"human"</span>: &#123;</span><br><span class="line">      <span class="string">"name"</span>: <span class="string">"Luke Skywalker"</span>,</span><br><span class="line">      <span class="string">"height"</span>: <span class="number">5.6430448</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>参数可以是很多不同的类型。在上面的例子中，我们使用了一个枚举类型，它表示一组有限的选项之一（在这种情况下是长度单位，METER或FOOT）。 GraphQL带有默认的类型，但是GraphQL服务器也可以声明自定义类型。只要能将它们序列化为可传输的格式。</p>
<h2 id="别名（Aliases）"><a href="#别名（Aliases）" class="headerlink" title="别名（Aliases）"></a>别名（Aliases）</h2><p>也许您已经注意到，相对应的结果字段名与查询字段名相同，但却不包括该字段的查询参数，因此您不能直接使用不同的参数查询相同的字段。这就是为什么你需要别名的原因。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  empireHero: hero(episode: EMPIRE) &#123;</span><br><span class="line">    name</span><br><span class="line">  &#125;</span><br><span class="line">  jediHero: hero(episode: JEDI) &#123;</span><br><span class="line">    name</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="string">"data"</span>: &#123;</span><br><span class="line">    <span class="string">"empireHero"</span>: &#123;</span><br><span class="line">      <span class="string">"name"</span>: <span class="string">"Luke Skywalker"</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="string">"jediHero"</span>: &#123;</span><br><span class="line">      <span class="string">"name"</span>: <span class="string">"R2-D2"</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="片段（Fragments）"><a href="#片段（Fragments）" class="headerlink" title="片段（Fragments）"></a>片段（Fragments）</h2><p>假设我们的应用中存在一个比较复杂的页面，可以一次性展示两个角色并列出他们的朋友信息。可以想象，这样一个查询可能会很快变得复杂，因为我们需要重复写角色字段至少两次。</p>
<p>这就是为什么GraphQL包含“片段”这种可重用单元。片段让您构建一组字段，然后我们可以将它们包含在需要的查询中。以下是使用片段解决上述情况的示例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  leftComparison: hero(episode: EMPIRE) &#123;</span><br><span class="line">    ...comparisonFields</span><br><span class="line">  &#125;</span><br><span class="line">  rightComparison: hero(episode: JEDI) &#123;</span><br><span class="line">    ...comparisonFields</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">fragment comparisonFields on Character &#123;</span><br><span class="line">  name</span><br><span class="line">  appearsIn</span><br><span class="line">  friends &#123;</span><br><span class="line">    name</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">&#123;</span><br><span class="line">  <span class="string">"data"</span>: &#123;</span><br><span class="line">    <span class="string">"leftComparison"</span>: &#123;</span><br><span class="line">      <span class="string">"name"</span>: <span class="string">"Luke Skywalker"</span>,</span><br><span class="line">      <span class="string">"appearsIn"</span>: [</span><br><span class="line">        <span class="string">"NEWHOPE"</span>,</span><br><span class="line">        <span class="string">"EMPIRE"</span>,</span><br><span class="line">        <span class="string">"JEDI"</span></span><br><span class="line">      ],</span><br><span class="line">      <span class="string">"friends"</span>: [</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="string">"name"</span>: <span class="string">"Han Solo"</span></span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="string">"name"</span>: <span class="string">"Leia Organa"</span></span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="string">"name"</span>: <span class="string">"C-3PO"</span></span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="string">"name"</span>: <span class="string">"R2-D2"</span></span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="string">"rightComparison"</span>: &#123;</span><br><span class="line">      <span class="string">"name"</span>: <span class="string">"R2-D2"</span>,</span><br><span class="line">      <span class="string">"appearsIn"</span>: [</span><br><span class="line">        <span class="string">"NEWHOPE"</span>,</span><br><span class="line">        <span class="string">"EMPIRE"</span>,</span><br><span class="line">        <span class="string">"JEDI"</span></span><br><span class="line">      ],</span><br><span class="line">      <span class="string">"friends"</span>: [</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="string">"name"</span>: <span class="string">"Luke Skywalker"</span></span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="string">"name"</span>: <span class="string">"Han Solo"</span></span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="string">"name"</span>: <span class="string">"Leia Organa"</span></span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>如果重复这些字段，您可以看到上述查询将如何重复。片段的概念经常用于将复杂的应用程序数据需求分解成更小的块，特别是当您需要将大量具有不同片段的UI组件合并到一个初始数据请求时。</p>
<h2 id="变量（variables）"><a href="#变量（variables）" class="headerlink" title="变量（variables）"></a>变量（variables）</h2><p>到目前为止，我们一直在查询字符串中写入所有的参数。 但在大多数应用程序中，字段的参数将是动态的：例如，可能会有一个下拉列表，您可以选择您感兴趣的星球大战插曲，或搜索字段或一组过滤器。</p>
<p>在查询字符串中直接传递这些动态参数并不是一个好主意，因为我们的客户端代码需要在运行时动态地处理查询字符串，并将其序列化为特定于图形的格式。 相反，GraphQL具有将查询中的动态值参数化的一级方法(first-class way)，并将其作为单独的字典传递。 这些值称为 <em>变量</em> 。</p>
<p>当开始使用变量之时，我们需要做三件事情：</p>
<ol>
<li>用<code>$variableName</code>替换查询语句中静态的值</li>
<li>声明<code>$variableName</code>为一个被查询语句接收的变量之一</li>
<li>将<code>$variableName: value</code>写入到一种传输专用的变量字典中(通常是JSON)，用来与查询语句分别传输到服务器上。</li>
</ol>
<p>整合后的结果：</p>
<ul>
<li><p>query</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">query HeroNameAndFriends($episode: Episode) &#123;</span><br><span class="line">  hero(episode: $episode) &#123;</span><br><span class="line">    name</span><br><span class="line">    friends &#123;</span><br><span class="line">      name</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>variables</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"episode"</span>: <span class="string">"JEDI"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>result</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"data"</span>: &#123;</span><br><span class="line">    <span class="attr">"hero"</span>: &#123;</span><br><span class="line">      <span class="attr">"name"</span>: <span class="string">"R2-D2"</span>,</span><br><span class="line">      <span class="attr">"friends"</span>: [</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="attr">"name"</span>: <span class="string">"Luke Skywalker"</span></span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="attr">"name"</span>: <span class="string">"Han Solo"</span></span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="attr">"name"</span>: <span class="string">"Leia Organa"</span></span><br><span class="line">        &#125;</span><br><span class="line">      ]</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>现在，在我们的客户端代码中，我们可以简单地传递一个不同的变量，而不需要构造一个全新的查询。 这通常也是一个好的做法，表示我们的查询中的哪些参数预期是动态的 - 我们不应该使用字符串插值来从用户提供的值构造查询。</p>
<h3 id="变量定义"><a href="#变量定义" class="headerlink" title="变量定义"></a>变量定义</h3><p>变量定义是上面查询中的（<code>$episode：Episode</code>）部分。 它的作用就像类型语言中函数的参数定义一样。 它列出所有变量，前缀为$，后跟其类型（当前为<code>Episode</code>）。</p>
<p>所有声明的变量必须是标量，枚举或输入对象类型。 因此，如果要将复杂对象传递到字段中，则需要知道在服务器上匹配的输入类型。 在“架构”页面上了解有关输入对象类型的更多信息。</p>
<p>变量定义可以是可选的或必需的。 在上面的情况下，因为没有！ 在Episode类型后面，所以它是可选的。 但是，如果要将变量传递给需要非空参数的字段，那么该变量也必须是必需的。</p>
<p>要了解有关这些变量定义的语法的更多信息，学习GraphQL模式语言非常有用。 模式语言在Schema页面中有详细的说明。</p>
<h3 id="默认变量"><a href="#默认变量" class="headerlink" title="默认变量"></a>默认变量</h3><p>可以在变量的类型声明后面添加该变量的默认值</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">query HeroNameAndFriends($episode: Episode = &quot;JEDI&quot;) &#123;</span><br><span class="line">  hero(episode: $episode) &#123;</span><br><span class="line">    name</span><br><span class="line">    friends &#123;</span><br><span class="line">      name</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="操作名（Operation-name）"><a href="#操作名（Operation-name）" class="headerlink" title="操作名（Operation  name）"></a>操作名（Operation  name）</h2><p>从上面的查询例子我们可以看到一个<code>HeroNameAndFriends</code>的操作名。但到目前为止，我们大部分是在速记语法，省略查询关键字和查询名称，但在生产中，这钟写法会使我们的代码不明确。</p>
<p>想想这就像你最喜欢的编程语言中的函数名。 例如，在JavaScript中，我们可以轻松地使用匿名函数，但是当我们给一个函数一个名字时，跟踪它更容易，调试我们的代码，并在被调用时记录。 以同样的方式，GraphQL查询和变量名称以及片段名称可以作为服务器端的一个有用的调试工具来识别不同的GraphQL请求。</p>
<h2 id="指令（Directives）"><a href="#指令（Directives）" class="headerlink" title="指令（Directives）"></a>指令（Directives）</h2><p>我们上面讨论了变量如何使我们避免进行手动字符串插值来构造动态查询。 在参数中传递变量解决了这些问题的一部分，但是我们也可能需要一种使用变量来动态地更改查询的结构和形状的方法。 例如，我们可以想象一个UI组件，它具有一个总结和详细的视图，其中一个包含比另一个更多的字段。让我们来为这样的组件构建一个查询语句：</p>
<ul>
<li><p>query</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">query Hero($episode: Episode, $withFriends: Boolean!) &#123;</span><br><span class="line">  hero(episode: $episode) &#123;</span><br><span class="line">    name</span><br><span class="line">    friends @include(if: $withFriends) &#123;</span><br><span class="line">      name</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>variables</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"episode"</span>: <span class="string">"JEDI"</span>,</span><br><span class="line">  <span class="attr">"withFriends"</span>: <span class="literal">false</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>result</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"data"</span>: &#123;</span><br><span class="line">    <span class="attr">"hero"</span>: &#123;</span><br><span class="line">      <span class="attr">"name"</span>: <span class="string">"R2-D2"</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>尝试编辑上面的变量（比如将<code>true</code>传给<code>withFriends</code>），看看结果如何变化。</p>
<p>我们需要在GraphQL中使用一个新功能，称为一个指令。 一个指令可以附加到字段或片段包含，并且可以以服务器的任何方式影响查询的执行。 核心GraphQL规范仅包含两个指令，这些指令必须由任何符合规范的GraphQL服务器实现支持：</p>
<ul>
<li><code>@include(if: Boolean)</code> 仅当参数为<code>true</code>时返回结果才包括这个字段</li>
<li><code>@skip(if: Boolean)</code> 当参数为<code>true</code>时跳过这个字段</li>
</ul>
<p>指令可用于摆脱需要执行字符串操作以在查询中添加和删除字段的情况。 服务器实现也可以通过定义全新的指令来添加实验功能。</p>
<h2 id="修改（Mutations）"><a href="#修改（Mutations）" class="headerlink" title="修改（Mutations）"></a>修改（Mutations）</h2><p>大多数关于GraphQL的讨论集中于数据获取，但是任何完整的数据平台也需要一种修改服务器端数据的方法。</p>
<p>在REST中，任何请求可能会导致在服务器上造成一些副作用，但按照惯例，建议不要使用GET请求来修改数据。 GraphQL是类似的：技术上任何查询都可以被实现来进行数据写入。 但是，建立一个约定，任何导致写入的操作都应该通过修改操作显式发送。</p>
<p>就像查询一样，如果修改字段返回一个对象类型，可以要求嵌套字段。 这可以在更新后获取对象的新状态。 我们来看一个简单的例子：</p>
<ul>
<li><p>mutation</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) &#123;</span><br><span class="line">  createReview(episode: $ep, review: $review) &#123;</span><br><span class="line">    stars</span><br><span class="line">    commentary</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>varialbes</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"ep"</span>: <span class="string">"JEDI"</span>,</span><br><span class="line">  <span class="attr">"review"</span>: &#123;</span><br><span class="line">    <span class="attr">"stars"</span>: <span class="number">5</span>,</span><br><span class="line">    <span class="attr">"commentary"</span>: <span class="string">"This is a great movie!"</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>result</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"data"</span>: &#123;</span><br><span class="line">    <span class="attr">"createReview"</span>: &#123;</span><br><span class="line">      <span class="attr">"stars"</span>: <span class="number">5</span>,</span><br><span class="line">      <span class="attr">"commentary"</span>: <span class="string">"This is a great movie!"</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>注意<code>createReview</code>字段是如何返回新创建的<code>review</code>中的<code>commentary</code>和<code>stars</code>字段的。 这在修改已有字段的时候尤其有用，例如，当增加一个字段时，我们可以通过一个请求来同时修改该字段并查询该字段的新值。</p>
<p>您可能还会注意到，在本示例中，我们传入的评论变量不是标量。 它是一个输入对象类型，可以作为参数传入的特殊种类的对象类型。 详细了解“架构”页面上的输入类型。</p>
<h3 id="修改多个字段"><a href="#修改多个字段" class="headerlink" title="修改多个字段"></a>修改多个字段</h3><p>像查询操作一样，一个修改操作可以包含多个字段，但是两者之间有一个重大的差异：   </p>
<p><strong>查询操作是并行的，而修改操作是串行的</strong></p>
<p>这意味着，如果我们在一个修改操作中两次修改<code>incremenetCredits</code>字段的操作，第一个操作在保证结束后才会执行第二个操作。避免出现竞争情况。</p>
<h2 id="内联片段（inline-Fragments）"><a href="#内联片段（inline-Fragments）" class="headerlink" title="内联片段（inline Fragments）"></a>内联片段（inline Fragments）</h2><p>跟其他类型系统一样，GraphQL也可以定义接口（Interfaces）和联合类型（Union Types）。详情见schema guide</p>
<p>你可以使用内联片段来访问一个接口或者联合类型中所包含的数据。用下面这个例子可以很方便的说明：</p>
<ul>
<li><p>query</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">query HeroForEpisode($ep: Episode!) &#123;</span><br><span class="line">  hero(episode: $ep) &#123;</span><br><span class="line">    name</span><br><span class="line">    ... on Droid &#123;</span><br><span class="line">      primaryFunction</span><br><span class="line">    &#125;</span><br><span class="line">    ... on Human &#123;</span><br><span class="line">      height</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>variables</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"ep"</span>: <span class="string">"JEDI"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>result</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"data"</span>: &#123;</span><br><span class="line">    <span class="attr">"hero"</span>: &#123;</span><br><span class="line">      <span class="attr">"name"</span>: <span class="string">"R2-D2"</span>,</span><br><span class="line">      <span class="attr">"primaryFunction"</span>: <span class="string">"Astromech"</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>在这个查询中，<code>hero</code>字段返回类型为<code>Character</code>，它可能是<code>Human</code>或<code>Droid</code>，这取决于参数<code>episode</code>。 在直接选择中，您只能访问<code>Character</code>接口中存在的字段，如<code>name</code>。</p>
<p>要访问具体类型的字段，您需要使用特定类型（type condition）的内联片段。 第一个片段在<code>Droid</code>上被标记为<code>...</code>，所以只有当从<code>hero</code>返回的<code>Character</code>是<code>Droid</code>类型时，<code>primaryFunction</code>字段才会被执行。 类似于<code>Human</code>类型中的<code>height</code>字段。</p>
<p>命名片段也可以以相同的方式使用，因为命名片段始终包含限定类型。</p>
<h3 id="元字段（Meta-fields）"><a href="#元字段（Meta-fields）" class="headerlink" title="元字段（Meta fields）"></a>元字段（Meta fields）</h3><p>鉴于有些情况下您不知道从GraphQL服务返回的类型，您需要一些方法来确定如何处理客户端上的数据。 GraphQL允许您在查询中的任何位置请求<code>__typename</code>，一个元字段，以获取该点上对象类型的名称。</p>
<ul>
<li><p>query</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  search(text: &quot;an&quot;) &#123;</span><br><span class="line">    __typename</span><br><span class="line">    ... on Human &#123;</span><br><span class="line">      name</span><br><span class="line">    &#125;</span><br><span class="line">    ... on Droid &#123;</span><br><span class="line">      name</span><br><span class="line">    &#125;</span><br><span class="line">    ... on Starship &#123;</span><br><span class="line">      name</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>result</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"data"</span>: &#123;</span><br><span class="line">    <span class="attr">"search"</span>: [</span><br><span class="line">      &#123;</span><br><span class="line">        <span class="attr">"__typename"</span>: <span class="string">"Human"</span>,</span><br><span class="line">        <span class="attr">"name"</span>: <span class="string">"Han Solo"</span></span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        <span class="attr">"__typename"</span>: <span class="string">"Droid"</span>,</span><br><span class="line">        <span class="attr">"name"</span>: <span class="string">"Leia Organa"</span></span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        <span class="attr">"__typename"</span>: <span class="string">"Starship"</span>,</span><br><span class="line">        <span class="attr">"name"</span>: <span class="string">"TIE Advanced x1"</span></span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>在上述查询中，<code>search</code>返回可以是三个选项之一的联合类型。 在没有<code>__typename</code>字段的情况下，不可能将客户端的不同类型告诉客户端。</p>
<p>GraphQL服务提供了少量的元字段，其余的公开 于“内省”系统。</p>

        </div>

        <blockquote class="post-copyright">
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2017-11-22T17:13:31.653Z" itemprop="dateUpdated">2017-11-23 01:13:31</time>
</span><br>


        
    </div>
    <footer>
        <a href="http://lishangying.github.io">
            <img src="/img/avatar.jpg" alt="Sailing">
            Sailing
        </a>
    </footer>
</blockquote>

        


        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/GraphQL/">GraphQL</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://lishangying.github.io/2017/08/15/GraphQL Learn (1) - Queries and Mutations/&title=《GraphQL Learn (1) - Queries and Mutations》 — Sailing&pic=http://lishangying.github.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://lishangying.github.io/2017/08/15/GraphQL Learn (1) - Queries and Mutations/&title=《GraphQL Learn (1) - Queries and Mutations》 — Sailing&source=在此页面上，你将详细了解如何查询GrahQL服务器。
字段（Fields）最简单的，GraphQL是关于要求对象上的特定字段。我们先来看一个非常简单的查询..." data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://lishangying.github.io/2017/08/15/GraphQL Learn (1) - Queries and Mutations/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《GraphQL Learn (1) - Queries and Mutations》 — Sailing&url=http://lishangying.github.io/2017/08/15/GraphQL Learn (1) - Queries and Mutations/&via=http://lishangying.github.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://lishangying.github.io/2017/08/15/GraphQL Learn (1) - Queries and Mutations/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2017/12/13/《c和指针》基础/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">《C和指针》基础</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2017/03/20/beautifull-i3/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">体验I3之美</h4>
      </a>
    </div>
  
</nav>



    














</article>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
                <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            
            <span>博客内容遵循 <a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">知识共享 署名 - 非商业性 - 相同方式共享 4.0 国际协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p><span>Sailing &copy; 2015 - 2018</span>
            <span>
                
                Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
            </span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://lishangying.github.io/2017/08/15/GraphQL Learn (1) - Queries and Mutations/&title=《GraphQL Learn (1) - Queries and Mutations》 — Sailing&pic=http://lishangying.github.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://lishangying.github.io/2017/08/15/GraphQL Learn (1) - Queries and Mutations/&title=《GraphQL Learn (1) - Queries and Mutations》 — Sailing&source=在此页面上，你将详细了解如何查询GrahQL服务器。
字段（Fields）最简单的，GraphQL是关于要求对象上的特定字段。我们先来看一个非常简单的查询..." data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://lishangying.github.io/2017/08/15/GraphQL Learn (1) - Queries and Mutations/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《GraphQL Learn (1) - Queries and Mutations》 — Sailing&url=http://lishangying.github.io/2017/08/15/GraphQL Learn (1) - Queries and Mutations/&via=http://lishangying.github.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://lishangying.github.io/2017/08/15/GraphQL Learn (1) - Queries and Mutations/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: false };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>






<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>





</body>
</html>
